#include "IRA.h"

/* ---<>-----------------------------------
      StartComPort()
---------------------------------------- */
int StartComPort()
{
    //initialize the com port
    return comPortInit(1000000,1000,1000);
}

/* ---<>-----------------------------------
      StartDaq(int frequency, int gains[])
---------------------------------------- */
/*int StartDaq(int frequency, GAIN_ENUM gains[])
{
    unsigned char packetLength;
    bool success = 0;
    stopWatch timer, timer2;
    timer2.start();

    //while (timer2.split() < 1)
    //{
        DAQ.sendStopProgram();

        DAQ.sendAdcInit(ADC_CH0_bp,gains[0]); //DAQ.sendAdcInit(ADC_CH0_bp,ADC_CH_GAIN_1X_gc);
        DAQ.sendAdcInit(ADC_CH1_bp,gains[1]); //DAQ.sendAdcInit(ADC_CH1_bp,ADC_CH_GAIN_1X_gc);
        DAQ.sendAdcInit(ADC_CH2_bp,gains[2]); //DAQ.sendAdcInit(ADC_CH2_bp,ADC_CH_GAIN_1X_gc);
        DAQ.sendAdcInit(ADC_CH3_bp,gains[3]); //DAQ.sendAdcInit(ADC_CH3_bp,ADC_CH_GAIN_1X_gc);

        DAQ.sendDacEnable(DAC_CH0_bp);
        DAQ.sendDacEnable(DAC_CH1_bp);

        //DAQ.sendDigitalInEnable();

        //need this for the ouputSuperPacketExample
        //DAQ.sendDigitalOutEnable(0xFFFF);

        //DAQ.sendEncoderInit(PLOC_D1,1,0,0,DIGFILT_6SAMPLES_gc,1024);
        //DAQ.sendEncoderInit(PLOC_D4,0,1,1,DIGFILT_6SAMPLES_gc,1024);

        //need these for the actuatorSuperPacket example
        //DAQ.sendMotorEnable(0x8);
        //DAQ.sendServoEnable(0x4);

        DAQ.sendSetTimerFreq(frequency);
        DAQ.sendStartProgram();

        timer.pause(0.05);
        printf("\n\n Trying to find DAQ response to start \n");
        comPortGet(1,packetLength);

        if (DAQ.analogIn[0].enable == 1 && DAQ.analogIn[1].enable == 1 && DAQ.analogIn[2].enable == 1 && DAQ.analogIn[3].enable == 1 && DAQ.analogOut[0].enable == 1 && DAQ.analogOut[1].enable == 1)
        {
            success = 1;
        }
    //}

    if (success == 0) { printf("FALIED to open Daq \n"); exit(0); }
    printf("DAQ Opened! \n");
    data.erase(data.begin(),data.end());
    return success;
}*/

/* ---<>-----------------------------------
      ReadDaq()
---------------------------------------- */
/*
int ReadDaq(double aIn[], int count)
{
        unsigned char packetLength;
        int returnVal;
        if (count < 2)
        {
            returnVal = comPortGet(0,packetLength);
        }
        else
        {
            returnVal = comPortGet(1,packetLength);
        }

        printf("Data available: %d \n",data.size());

        if (returnVal != 1) { return returnVal; }

        if (data.size() > 0)
        {
            count = (data.size() >= count) ? count : data.size();
            for (int ii = 0; ii < count; ii ++)
            {
                memcpy( aIn+ii*4, data.front().data(), 4*sizeof(double) );
                data.pop_front();
            }
        }
        else
        {
            return -11;
        }
        return count;
}
*/
/* ---<>-----------------------------------
      StopDaq()
---------------------------------------- */
void StopDaq()
{
    printf("\n\nStoping Daq \n");
    DAQ.sendStopProgram();
    stopWatch timer;
    timer.pause(0.1);
    DAQ.sendStopProgram();
    FT_Close(handle);
}
